package com.xbongbong.sys.enums;

import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 钉钉触发器id
 * 创建时间 2021/5/26 9:20 AM
 * 修改时间 2021/5/26 9:20 AM
 * @author chy
 */
@Getter
public enum DdTriggerEnum {

    /**
     * 标准客户模型触发器id
     */
    //正式
//    STANDARD_CUSTOMER_TRIGGER_ID("******","standardCustomerTriggerId", "标准客户模型触发器id", XbbRefTypeEnum.CUSTOMER),
    //测试
//    STANDARD_CUSTOMER_TRIGGER_ID("TRIGGER-1014C915D5EB0B081F4F000D","standardCustomerTriggerId", "标准客户模型触发器id", XbbRefTypeEnum.CUSTOMER),
    STANDARD_CUSTOMER_ADD_TRIGGER_ID("G-TRI-10166FDE3CA50B01B8D0000B","standardCustomerAddTriggerId", "add", "标准客户模型添加触发器id", XbbRefTypeEnum.CUSTOMER),
    STANDARD_CUSTOMER_UPDATE_TRIGGER_ID("G-TRI-10166FDE76CF0B01B8D0000O","standardCustomerUpdateTriggerId", "update", "标准客户模型编辑触发器id", XbbRefTypeEnum.CUSTOMER),
    STANDARD_CUSTOMER_DELETE_TRIGGER_ID("G-TRI-10166FDEB64D0B01B8D00008","standardCustomerDeleteTriggerId", "delete", "标准客户模型删除触发器id", XbbRefTypeEnum.CUSTOMER),
    /**
     * 标准合同模型触发器id
     */
    //正式
//    STANDARD_CONTRACT_TRIGGER_ID("******","standardContractTriggerId", "标准合同模型触发器id", XbbRefTypeEnum.CONTRACT),
    //测试
//    STANDARD_CONTRACT_TRIGGER_ID("TRIGGER-1014C911EB140B174A50000W","standardContractTriggerId", "标准合同模型触发器id", XbbRefTypeEnum.CONTRACT),
    STANDARD_CONTRACT_ADD_TRIGGER_ID("G-TRI-10166FD4DDF40B1738B3000Z","standardContractAddTriggerId", "add", "标准合同模型添加触发器id", XbbRefTypeEnum.CONTRACT),
    STANDARD_CONTRACT_UPDATE_TRIGGER_ID("G-TRI-10166FD53D220B01B8D00006","standardContractUpdateTriggerId", "update", "标准合同模型编辑触发器id", XbbRefTypeEnum.CONTRACT),
    STANDARD_CONTRACT_DELETE_TRIGGER_ID("G-TRI-10166FD586AD0B1738B3000H","standardContractDeleteTriggerId", "delete", "标准合同模型删除触发器id", XbbRefTypeEnum.CONTRACT),
    /**
     * 标准销售机会模型触发器id
     */
    //正式
//    STANDARD_CONTRACT_TRIGGER_ID("******","standardContractTriggerId", "标准合同模型触发器id", XbbRefTypeEnum.CONTRACT),
    //测试
//    STANDARD_SALES_OPPORTUNITY_TRIGGER_ID("XXX","standardSalesOpportunityTriggerId", "标准销售机会模型触发器id", XbbRefTypeEnum.SALES_OPPORTUNITY),
    STANDARD_SALES_OPPORTUNITY_ADD_TRIGGER_ID("G-TRI-1016C713185D0B0FED310002","standardSalesOpportunityAddTriggerId", "add", "标准销售机会模型添加触发器id", XbbRefTypeEnum.SALES_OPPORTUNITY),
    STANDARD_SALES_OPPORTUNITY_UPDATE_TRIGGER_ID("G-TRI-1016C71923410B081F4F000X","standardSalesOpportunityUpdateTriggerId", "update", "标准销售机会模型编辑触发器id", XbbRefTypeEnum.SALES_OPPORTUNITY),
    STANDARD_SALES_OPPORTUNITY_DELETE_TRIGGER_ID("G-TRI-1016C71DF5060B0FED310006","standardSalesOpportunityDeleteTriggerId", "delete", "标准销售机会模型删除触发器id", XbbRefTypeEnum.SALES_OPPORTUNITY),
    /**
     * 标准产品模型触发器id
     */
    //正式
//    STANDARD_PRODUCT_TRIGGER_ID("*******","standardProductTriggerId", "标准产品模型触发器id", XbbRefTypeEnum.PRODUCT),
    //测试
//    STANDARD_PRODUCT_TRIGGER_ID("TRIGGER-1014C9150E2B0B83EA60000Z","standardProductTriggerId", "标准产品模型触发器id", XbbRefTypeEnum.PRODUCT),
    STANDARD_PRODUCT_ADD_TRIGGER_ID("G-TRI-10166FDC77F30B1738B30001","standardProductAddTriggerId", "add", "标准产品模型添加触发器id", XbbRefTypeEnum.PRODUCT),
    STANDARD_PRODUCT_UPDATE_TRIGGER_ID("G-TRI-10166FDCB35C0B1738B3000S","standardProductUpdateTriggerId", "update", "标准产品模型编辑触发器id", XbbRefTypeEnum.PRODUCT),
    STANDARD_PRODUCT_DELETE_TRIGGER_ID("G-TRI-10166FDCF3370B1738B3000R","standardProductDeleteTriggerId", "delete", "标准产品模型删除触发器id", XbbRefTypeEnum.PRODUCT),
    /**
     * 标准产品分类模型触发器id
     */
    //正式
//    STANDARD_PRODUCT_CATEGORY_TRIGGER_ID("triggerId","standardProductCategoryTriggerId", "标准产品分类模型触发器id", XbbRefTypeEnum.PRODUCT_CATEGORY),
    //测试
//    STANDARD_PRODUCT_CATEGORY_TRIGGER_ID("TRIGGER-1014C91567830B174A500007","standardProductCategoryTriggerId", "标准产品分类模型触发器id", XbbRefTypeEnum.PRODUCT_CATEGORY),
    STANDARD_PRODUCT_CATEGORY_ADD_TRIGGER_ID("G-TRI-10166FDAF8090B1738B30005","standardProductCategoryAddTriggerId", "add", "标准产品分类模型添加触发器id", XbbRefTypeEnum.PRODUCT_CATEGORY),
    STANDARD_PRODUCT_CATEGORY_UPDATE_TRIGGER_ID("G-TRI-10166FDB40970B01B8D00009","standardProductCategoryUpdateTriggerId", "update", "标准产品分类模型编辑触发器id", XbbRefTypeEnum.PRODUCT_CATEGORY),
    STANDARD_PRODUCT_CATEGORY_DELETE_TRIGGER_ID("G-TRI-10166FDBDFD60B01B8D00003","standardProductCategoryDeleteTriggerId", "delete", "标准产品分类模型删除触发器id", XbbRefTypeEnum.PRODUCT_CATEGORY),
    /**
     * 标准仓库模型触发器id
     */
    //正式
//    STANDARD_WAREHOUSE_TRIGGER_ID("*******","standardWarehouseTriggerId", "标准仓库模型触发器id", XbbRefTypeEnum.WAREHOUSE),
    //测试
//    STANDARD_WAREHOUSE_TRIGGER_ID("TRIGGER-1014C91463270B83EA60000O","standardWarehouseTriggerId", "标准仓库模型触发器id", XbbRefTypeEnum.WAREHOUSE),
    STANDARD_WAREHOUSE_ADD_TRIGGER_ID("G-TRI-10166FE217F30B1738B3000Z","standardWarehouseAddTriggerId", "add", "标准仓库模型添加触发器id", XbbRefTypeEnum.WAREHOUSE),
    STANDARD_WAREHOUSE_UPDATE_TRIGGER_ID("G-TRI-10166FE2570E0B1738B3000J","standardWarehouseUpdateTriggerId", "update", "标准仓库模型编辑触发器id", XbbRefTypeEnum.WAREHOUSE),
    STANDARD_WAREHOUSE_DELETE_TRIGGER_ID("G-TRI-10166FE298EA0B1738B3000C","standardWarehouseDeleteTriggerId", "delete", "标准仓库模型删除触发器id", XbbRefTypeEnum.WAREHOUSE),
    /**
     * 标准回款计划模型触发器id
     */
    //正式
//    STANDARD_PAYMENT_TRIGGER_ID("*******","standardPaymentTriggerId", "标准回款计划模型触发器id", XbbRefTypeEnum.PAYMENT),
    //测试
//    STANDARD_PAYMENT_TRIGGER_ID("TRIGGER-10152B6D56650B081F4F000W","standardPaymentTriggerId", "标准回款计划模型触发器id", XbbRefTypeEnum.PAYMENT),
    STANDARD_PAYMENT_ADD_TRIGGER_ID("G-TRI-10166FD1B02B0B1738B30007","standardPaymentAddTriggerId", "add", "标准回款计划模型添加触发器id", XbbRefTypeEnum.PAYMENT),
    STANDARD_PAYMENT_UPDATE_TRIGGER_ID("G-TRI-10166FD352FC0B01B8D0000Y","standardPaymentUpdateTriggerId", "update", "标准回款计划模型编辑触发器id", XbbRefTypeEnum.PAYMENT),
    STANDARD_PAYMENT_DELETE_TRIGGER_ID("G-TRI-10166FD3E06E0B01B8D0000Q","standardPaymentDeleteTriggerId", "delete", "标准回款计划模型删除触发器id", XbbRefTypeEnum.PAYMENT),
    /**
     * 标准回款单触发器id
     */
    //正式
//    STANDARD_PAYMENT_SHEET_TRIGGER_ID("*******","standardPaymentSheetTriggerId", "标准回款单触发器id", XbbRefTypeEnum.PAYMENT_SHEET),
    //测试
//    STANDARD_PAYMENT_SHEET_TRIGGER_ID("TRIGGER-10152B6D564E0B83EA60000M","standardPaymentSheetTriggerId", "标准回款单触发器id", XbbRefTypeEnum.PAYMENT_SHEET),
    STANDARD_PAYMENT_SHEET_ADD_TRIGGER_ID("G-TRI-10166FD7EE9F0B01B8D00005","standardPaymentSheetAddTriggerId", "add", "标准回款单添加触发器id", XbbRefTypeEnum.PAYMENT_SHEET),
    STANDARD_PAYMENT_SHEET_UPDATE_TRIGGER_ID("G-TRI-10166FD850920B01B8D00004","standardPaymentSheetUpdateTriggerId", "update", "标准回款单编辑触发器id", XbbRefTypeEnum.PAYMENT_SHEET),
    STANDARD_PAYMENT_SHEET_DELETE_TRIGGER_ID("G-TRI-10166FD8E82C0B1738B3000A","standardPaymentSheetDeleteTriggerId", "delete", "标准回款单删除触发器id", XbbRefTypeEnum.PAYMENT_SHEET),
    /**
     * UNKNOWN
     */
    UNKNOWN("unknown","unknown","unknown", "未知模型触发器id", XbbRefTypeEnum.UNKNOWN),
    ;

    /** 枚举值 -- */
    private final String triggerId;
    /** 枚举描述 --英文名称*/
    private final String alias;
    /** 执行动作操作 */
    private final String operate;
    /** 枚举信息--中文名称 */
    private final String name;
    private final XbbRefTypeEnum xbbRefTypeEnum;

    DdTriggerEnum(String triggerId, String alias, String operate, String name, XbbRefTypeEnum xbbRefTypeEnum) {
        this.triggerId = triggerId;
        this.alias = alias;
        this.operate = operate;
        this.name = name;
        this.xbbRefTypeEnum = xbbRefTypeEnum;
    }

    /**
     * 获取全部枚举
     *
     * @return List<DdTriggerEnum>
     */
    public static List<DdTriggerEnum> getAllEnum() {
        List<DdTriggerEnum> list = new ArrayList<>();
        for (DdTriggerEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    /**
     * 根据code获取枚举
     * @return
     */
    public static DdTriggerEnum getByTriggerId(String triggerId) {
        if (triggerId == null) {
            return UNKNOWN;
        }
        for (DdTriggerEnum cache : values()) {
            if (Objects.equals(cache.getTriggerId(), triggerId)) {
                return cache;
            }
        }
        return UNKNOWN;
    }

    public static String getTriggerId(XbbRefTypeEnum xbbRefTypeEnum, String operate) {
        if (Objects.isNull(xbbRefTypeEnum) || Objects.isNull(operate)) {
            return null;
        }
        for (DdTriggerEnum cache : values()) {
            if (Objects.equals(cache.getXbbRefTypeEnum(), xbbRefTypeEnum)
            && Objects.equals(cache.getOperate(), operate)) {
                return cache.getTriggerId();
            }
        }
        return null;
    }

    public String getName() {
        return name;
    }


}
